#!/usr/bin/python3
# coding: utf-8
# file: datetime_.py
# 2018-06-13
import datetime
import time


def cal_time_diff(small_time, big_time):
	'计算2个日期的时间差'
	small_time=time.strptime(small_time,"%Y-%m-%d %H:%M:%S")   
	big_time=time.strptime(big_time,"%Y-%m-%d %H:%M:%S")  

	small_time=datetime.datetime(small_time[0],small_time[1],small_time[2],small_time[3],small_time[4],small_time[5])  
	big_time=datetime.datetime(big_time[0],big_time[1],big_time[2],big_time[3],big_time[4],big_time[5])  

	return big_time - small_time

def parse_diff(diff):
	'解析时间差'
	d = diff.days
	m, s = divmod(diff.seconds, 60)
	h, m = divmod(m, 60)

	if d > 0:
		print('赛前{day}天{hour}小时'.format(day=d, hour=h))
	elif d == 0:
		if h > 0:
			print('赛前{hour}小时{minute}分'.format(minute=m, hour=h))
		else:
			print('赛前{minute}分'.format(minute=m))
	else:
		print('已经开赛')

def example():
	date1 = '2018-06-14 22:03:00'
	date2 = '2018-06-14 23:02:00'
	diff = cal_time_diff(date1, date2)

	parse_diff(diff)
	
	





if __name__ == '__main__':
	example()
